package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;

import java.util.List;

public class MemberCenterPayWayAdapter extends BaseQuickAdapter<HousePayWayBean, BaseViewHolder> {
    ImageLoader mglideImage;
    int selectIndex=0;
    ItemClickBack mitemClickBack;
    public MemberCenterPayWayAdapter(@Nullable List<HousePayWayBean> data, ItemClickBack itemClickBack) {
        super(R.layout.membercenter_payway_item,data);
        mitemClickBack=itemClickBack;
    }

    @Override
    protected void convert(BaseViewHolder helper, HousePayWayBean item) {
        if (mglideImage == null) {
            mglideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        mglideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getIcon()).isCenterCrop(true)
                .imageView(helper.<ImageView>getView(R.id.popuwindow_pay_zfb_img))
                .build());
        helper.<TextView>getView(R.id.popuwindow_pay_zfb_txt).setText(item.getName());
        if (helper.getPosition()==selectIndex)
        {
            helper.<TextView>getView(R.id.popuwindow_pay_zfb_CheckBox).setBackgroundResource(R.drawable.checkbox_select_s);
            mitemClickBack.callBack(selectIndex);
        }else {
            helper.<TextView>getView(R.id.popuwindow_pay_zfb_CheckBox).setBackgroundResource(R.drawable.checkbox_select_n);
        }
        helper.<TextView>getView(R.id.popuwindow_pay_zfb_CheckBox).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectIndex=helper.getPosition();
                notifyDataSetChanged();

            }
        });
    }

    public void setItemClickBack(ItemClickBack mitemClickBack) {
        this.mitemClickBack = mitemClickBack;
    }

    public interface ItemClickBack{
        void callBack(int selectIndex);
    }
}
